/*
 * Copyright (C) 2018 Logos Technology Ltd.
 */

package com.logos.common.keepalive.deviceutil;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;

import com.logos.common.R;

import java.util.List;

/**
 * Created by llx on 2018/11/13.
 * 建议放在自己的项目中
 */
public final class XiaomiDeviceUtil {

    /**
     * 需要注意32行配置的package_label属性为你自己项目的app_name
     * 跳转应用详情的省电策略界面
     * @param context *
     * @return *
     */
    public static boolean toConfigApp(Context context) {
        try {
            Intent intent = new Intent("miui.intent.action.HIDDEN_APPS_CONFIG_ACTIVITY");
            intent.putExtra("package_name", context.getPackageName());
            intent.putExtra("package_label",
                    context.getResources().getString(R.string.app_name));

            List<ResolveInfo> resolveInfos = context
                    .getPackageManager()
                    .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
            if (resolveInfos.size() > 0) {
                context.startActivity(intent);
            }
            return true;
        } catch (Exception ex) {
            ex.printStackTrace();
            return false;
        }
    }
}

